<template>
  <div class="tag-list-comp">
    <div class="tag-list flex align-center">
      <div
        v-for="(item, index) in list"
        :key="item.name"
        class="tag-item pointer"
        :class="{ active: active === index }"
        @click="toggle(index)"
      >
        {{ item.name }}
      </div>
    </div>
  </div>
</template>
<script>
export default {
  name: 'TagList',
  props: {
    list: {
      type: Array,
      default() {
        return []
      }
    }
  },
  data() {
    return {
      active: 0
    }
  },
  methods: {
    toggle(index) {
      this.active = index
      this.$emit('get', index, this.list[index])
    }
  }
}
</script>
<style lang="scss" scoped>
.tag-list {
  border-radius: 15px;
  background: rgba(230, 237, 245, 1);
  box-sizing: border-box;
  padding: 2px 4px;
  .tag-item {
    font-size: 14px;
    font-weight: 500;
    color: rgba(110, 110, 110, 1);
    box-sizing: border-box;
    padding: 6px 12px;
    border-radius: 15px;
  }
  .tag-item.active {
    color: rgba(255, 255, 255, 1);
    background-color: rgba(63, 140, 255, 1);
  }
}
.dark {
  .tag-list {
    background: rgba(230, 237, 245, 0.4);
    .tag-item {
      color: rgba(255, 255, 255, 0.5);
    }
    .tag-item.active {
      color: #fff;
    }
  }
}
</style>
